
"""
faker生成测试数据

{"mobile":"#mobile#" }

[
{"mobile1":[sql,"SELECT code FROM tz_user WHERE user_mobile=123456"]},
{"mobile2":[response,"json表达式"]},
{"mobile3":[script,函数名称]},
]

"""

from faker import Faker
from tools.handle_mysql import mysql


class HandleFaker:
    def __init__(self):
        self.fk = Faker(locale="zh-cn")

    # 检查手机号是否已注册
    def __check_phone(self,phone):
        sql = "SELECT count(*) FROM tz_user WHERE user_mobile = '{}'".format(phone)
        # sql = "SELECT count(*) FROM tz_user WHERE user_mobile = '13550186653'"
        #查询数据库
        result = mysql.get_datas(sql=sql)
        print(result,type(result))
        return result

    #生成未注册的手机号
    def get_phone(self):
        while True:
            phone = self.fk.phone_number()
            result = self.__check_phone(phone=phone)[0]
            if result > 0:
                #重新跑一遍刚才的流程
                continue
            #查询数据库，看手机号是否被注册了
            else:
                print('返回的手机号：',phone,type(phone))
                return phone

if __name__ == '__main__':
    cl = HandleFaker()
    cl.get_phone()